/*
** Title: Dialog of approvement checking form for ICMS 
** Author: LU Yi Chen
** Date: Nov 2013
*/

$(document).ready(function() {
     var curDate = $.datepicker.formatDate('dd-M-yy', new Date());

     var jsDate = new Date();
     var curHours = jsDate.getHours();
     var curMin = jsDate.getMinutes();
     var formatedTime = curHours + ":" + curMin;

     var formatedDateTime = curDate + " " + formatedTime;

    $("#dialog-form").dialog({
        dialogClass: "no-close",
        autoOpen: false,
        height: 400,
        width: 350,
        modal: true,
        closeOnEscape:true,
        buttons: {
            "Invite": function() {
                var agencyListArr = [];
                $('#dialogTempAgencies tr td:first-child').each(function(index, val) {
                     agencyListArr.push($(this).text());
                });
                $.each(agencyListArr, function(index, val) {
                    $( "#approveAgencyTable" ).append( "<tr>" +
                        "<td>" + val+ "</td>" +
                        '<td style="color:#e0981c;">Waiting for approval</td>' +
                        "<td>Invited on " + formatedDateTime + "</td>" +
                        "</tr>" );
                });
                $( this ).dialog( "close" );
                $.jGrowl("New agencies are invited for approvement.")
            },
            Cancel: function() {
                $( this ).dialog( "close" );
            }
        }
    });

    $("#btnAdd2InviteList").click(function(event) {
        var agencyName2BAdded = $('#dialogAgencyName').val()
        $('#dialogTempAgencies').append('<tr><td>'+agencyName2BAdded+'</td><td><button class="listRemover" style="background: rgb(202, 60, 60);">Remove</button></td></tr>');
        $('.listRemover').click(function(event) {
            $(this).parents('tr').remove();
        });
    });






});